package com.security.config.security.authentication.username;

import com.security.domain.po.Account;
import lombok.Getter;
import lombok.Setter;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

/**
 * 用户名密码认证令牌
 *
 * @author DblSun
 */
public class UsernameAuthenticationToken extends AbstractAuthenticationToken {
    private final Object principal;
    private final Object credentials;
    @Setter
    @Getter
    private Account account;

    public UsernameAuthenticationToken(final Object principal, Object credentials) {
        super(null);
        this.principal = principal;
        this.credentials = credentials;
        this.setAuthenticated(false);
    }

    public UsernameAuthenticationToken(Object principal, Object credentials, Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
        this.principal = principal;
        this.credentials = credentials;
        this.setAuthenticated(true);
    }

    @Override
    public Object getPrincipal() {
        return this.principal;
    }

    @Override
    public Object getCredentials() {
        return this.credentials;
    }


}